package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        List<Book>books=new ArrayList<Book>();
        String pash="D:\\book.txt";
        String passh1="D:\\book1.txt";
        BufferedReader reader=null;
        BufferedWriter writer=null;
        try {
             reader=new BufferedReader(new FileReader(pash));
             String line="";
             while ((line=reader.readLine())!=null) {
                 String[] tokens = line.split("\t");
                 Book book = new Book();
                 book.bookNo =tokens[0];
                 book.bookName = tokens[1];
                 book.Version = tokens[2];
                 book.price=tokens[3];
                 book.sales=tokens[4];
//                 book.price = Double.parseDouble(tokens[3]);
//                 book.sales = Double.parseDouble(tokens[4]);
                 books.add(book);
             }
             int i=1;
             for (Book n:books){
                 if (i==3){
                     n.price=n.price+20;
                 }
                 if (i==4){
                     n.price=n.price+30;

                 }
             }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
             writer=new BufferedWriter(new FileWriter(passh1));
            for (Book b:books){
                writer.write(b.bookNo+" "
                +b.bookName+" " +b.Version+" "+b.price+" "+b.sales);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
